package com.echovin.esb.gateway.mapper;

import com.echovin.esb.gateway.model.GatewayErrorResponse;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface  GatewayErrorResponseMapper {
    @Select("select * from GATEWAY_ERROR_RESPONSE where SERVICE_ID is null")
    List<GatewayErrorResponse> getErrorResponse();
    @Select("select * from GATEWAY_ERROR_RESPONSE where SERVICE_ID is not null")
    List<GatewayErrorResponse> getDefaultErrorResponse();

    @SelectKey(keyProperty = "record.id", resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Options(keyProperty = "record.id", useGeneratedKeys = true)
    @Insert("insert into GATEWAY_ERROR_RESPONSE(ID,SERVICE_ID,ACTION_ID,ERROR_CODE,ERROR_RESPONSE,CREATER,CREATE_TIME) " +
            "values(#{record.id},#{record.serviceId},#{record.actionId},#{record.errorCode},#{record.errorResponse},#{record.creater},#{record.createTime})")
    int insert(@Param("record") GatewayErrorResponse record);

    @Update("update GATEWAY_ERROR_RESPONSE set IS_DELETE = 1, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where ACTION_ID = #{record.actionId}")
    int delete(GatewayErrorResponse record);

    @Update("update GATEWAY_ERROR_RESPONSE set ERROR_CODE = #{record.errorCode}, ERROR_RESPONSE = #{record.errorResponse}, UPDATER = #{record.updater}, UPDATE_TIME = #{record.updateTime} where ID = #{record.id}")
    int update(GatewayErrorResponse record);
}
